package logic

import (
	"context"
	"taobao_svc/models/mysql"

	"taobao_svc/internal/svc"
	"taobao_svc/taobao"

	"github.com/zeromicro/go-zero/core/logx"
)

type ImageAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewImageAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageAddLogic {
	return &ImageAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品封面
func (l *ImageAddLogic) ImageAdd(in *taobao.ImageAddRequest) (*taobao.ImageAddResponse, error) {
	// todo: add your logic here and delete this line

	image := mysql.Image{
		ProductId: int(in.ProductId),
		Img:       in.Img,
	}

	mysql.DB.Debug().Create(&image)

	return &taobao.ImageAddResponse{
		Id: int64(image.ID),
	}, nil
}
